package com.autumn.domain.entities;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import com.autumn.common.api.application.DataValidation;
import com.autumn.common.api.domain.entities.IEntity;
import com.autumn.mybatis.mapper.annotation.ColumnOrder;
import com.autumn.util.BeanUtils;
import com.autumn.validation.ValidationUtils;

/**
 * 实体抽象
 * 
 * @author 老码农
 *         <p>
 *         Description
 *         </p>
 * @date 2017-12-31 21:17:09
 * @param <TPrimaryKey>
 *            主键类型
 */
public abstract class AbstractEntity<TPrimaryKey> implements IEntity<TPrimaryKey>, DataValidation, EntityDataBean {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5901548351739663626L;
	
	@Id
	@ColumnOrder(-10000)
	@Column(name = "id", nullable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private TPrimaryKey id;	

	@Override
	public TPrimaryKey getId() {
		return id;
	}

	@Override
	public void setId(TPrimaryKey id) {
		this.id = id;
	}

	@Override
	public void valid() {
		ValidationUtils.validation(this);
	}

	/**
	 * 默认转换
	 * 
	 *
	 */
	@Override
	public void forNullToDefault() {
		BeanUtils.setDbEntityforNullToDefault(this);
	}
}
